package com.five.monkey.feign.provider.controller;

import com.five.monkey.vo.CommonVo;
import com.five.monkey.vo.TestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 狻猊
 * @date 2021/8/9 上午11:57
 */
@Api(value = "测试服务相关接口")
@RestController
@RequestMapping("/provider/test")
public class ProviderTestController {

    @GetMapping("/get")
    @ApiOperation(value = "测试get接口", notes = "测试get接口", response = CommonVo.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "name", value = "姓名", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "age", value = "年龄", required = true, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "score", value = "分数", defaultValue = "0.0f", paramType = "query", dataType = "Float")
    })
    public CommonVo<TestVo> testGet(@RequestParam("name") String name, @RequestParam("age") int age,
                            @RequestParam(value = "score", required = false, defaultValue = "0.0f") float score) {
        TestVo testVo = new TestVo(name, age, score);
        return CommonVo.ok(testVo);
    }

    @PostMapping("/post")
    @ApiOperation(value = "测试post接口", notes = "测试post接口", response = CommonVo.class)
    public CommonVo<TestVo> testPost(@RequestBody TestVo testVo) {
        testVo.changeName("hello ", "").changeAge(12).changeScore(0.3f);
        return CommonVo.ok(testVo);
    }
}
